<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			//方法三,获取元素添加时间监听
			function add(){
				let bt1 =document.querySelector("button");
				bt1.addEventListener("click",test);
				
			}
			function test(){
				alert("监听添加成功");
			}
		</script>
	</head>
	<body>
		<button >按钮</button>
		<!-- 方法一。 -->
		<button onclick="add()">添加事件监听</button>
		<button >移除事件监听</button>
		
		<script type="text/javascript">
			//方法二,获取元素后为元素赋值一个函数
			let bt3=document.querySelectorAll("button")[2];
			bt3.onclick=function(){
				let bt1 =document.querySelector("button");
				bt1.removeEventListener("click",test);
			}
		</script>
	</body>
</html>
